package com.simple.service.emp;

import java.util.List;
import java.util.Map;

import com.simple.service.common.SuggestCodeService;
import com.xunj.core.CoreDao;
import com.xunj.util.StateConst;

public class EmployeeService {
	
	private CoreDao dao;

	public EmployeeService(CoreDao dao) {
		this.dao = dao;
	}

	
	/**
	 * 创建员工信息快速检索码
	 * @param filePath
	 * @throws Exception
	 */
	public void getEmpSuggestCode(String filePath) throws Exception
	{
		StringBuffer codes = new StringBuffer("var emps = [");
		String hql = "select new Map(e.employeeCode as employeeCode," +
				"e.employeeName as employeeName,e.suggestCode as suggestCode) from EmpEmployee e" +
				" where e.state='"+StateConst.STATE_USE+"'";
		
		List list = dao.findAll(hql);
		String str=null;
		for(int i=0;i<list.size();i++)
		{
			Map emp = (Map) list.get(i);
			str="{"+emp.get("suggestCode")+",employeeName:\""+emp.get("employeeName")+"\",employeeCode:\""+emp.get("employeeCode")+"\"},";
			codes.append(str);
		}
		codes.append("{}];");
		SuggestCodeService scs = new SuggestCodeService(dao);
		scs.writeSuggestCodeToFile(codes.toString(),filePath);
	}
	
}
